﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XXN.Model;
using XXN.Model.Model;

namespace XXN.Service
{
    public class RecommendsService
    {
        public Shopping_MallEntities SB = new Shopping_MallEntities();

        public List<Recommends> GetRecommends(int page, int limit, out int count)
        {
            var shou = from item in SB.Recommends.Where(p => true)
                       select new Recommends
                       {
                           Rec_id = item.Rec_id,
                           Positionname = item.Positionname
                       };
            count = shou.Count();
            shou = shou.OrderBy(p => p.Rec_id);
            shou = shou.Skip((page - 1) * limit).Take(limit);
            return shou.ToList();
        }

        public int DelInfo(int id)
        {
            SB.Recommends.SingleOrDefault(p => p.Rec_id == id);
            return SB.SaveChanges();
        }

        public Recommend GetRecommends(int id)
        {
            var shou = SB.Recommends.Where(p => p.Rec_id == id).ToList().Select(
                x => new Recommend
                {
                    Rec_id = x.Rec_id,
                    Positionname = x.Positionname
                }).ToList();

            return shou.SingleOrDefault();
        }

        public int EditInfo(Recommend Cd)
        {
            SB.Entry(Cd).State = System.Data.Entity.EntityState.Modified;
            return SB.SaveChanges();
        }
    }
}